<template>
  <d2-container>
    <template slot="header">
      <headOwnerSearch @conditionChange="onSearch"></headOwnerSearch>
    </template>

    <el-table :data="tableData" style="width: 100%" stripe size="mini" v-loading="loading">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <sublistOwnerRoom></sublistOwnerRoom>
        </template>
      </el-table-column>
      <el-table-column prop="ownerName" label="业主姓名"></el-table-column>
      <el-table-column prop="ownerTel" label="业主电话"></el-table-column>
      <el-table-column prop="ownerIDNumber" label="业主身份证号"></el-table-column>
      <el-table-column align="right">
        <template slot="header" slot-scope="scope">
          <el-button type="primary" plain size="mini" @click="onAdd">新增</el-button>
        </template>
        <template slot-scope="scope">
          <el-button size="mini" type="success" plain @click="onRelation(scope.row)">关联套户</el-button>
          <el-button size="mini" type="success" plain @click="onUpdate(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <template slot="footer">
      <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
    </template>
    <dialogOwnerModify ref="dialogOwnerModify"></dialogOwnerModify>
    <dialogOwnerRoomRelation ref="dialogOwnerRoomRelation"></dialogOwnerRoomRelation>
  </d2-container>
</template>
<script>
import { mapActions } from "vuex";

export default {
  mounted() {
    this.loading = true;
    this.getOwnerList().then(result => {
      this.tableData = result;
      this.loading = false;
    });
  },
  data() {
    return {
      loading: false,
      tableData: []
    };
  },
  methods: {
    ...mapActions("pms/base.owner", ["getOwnerList"]),
    onAdd() {
      this.$refs.dialogOwnerModify.showDialog();
    },
    onUpdate(row) {
      this.$refs.dialogOwnerModify.showDialog(row);
    },
    onRelation(row) {
      this.$refs.dialogOwnerRoomRelation.showDialog(row);
    },
    onSearch(condition) {
      console.log(condition);
    }
  },
  components: {
    headOwnerSearch: () => import("./head-owner-search"),
    dialogOwnerModify: () => import("./dialog-owner-modify"),
    sublistOwnerRoom: () => import("./sublist-owner-room"),
    dialogOwnerRoomRelation: () => import("./dialog-owner-room-relation")
  }
};
</script>